package cn.com.jtang.wedding.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.jtang.wedding.dao.OrdersDao;
import cn.com.jtang.wedding.model.Orders;

public class OrdersDaoImpl extends BaseDaoImpl implements OrdersDao {
	private static final String ID = "id";
	private static final String ORDERNUM = "orderNum";
	private static final String USERID = "userId";
	private static final String ADMINUSERID = "adminUserId";
	private static final String ADMINUSERNAME = "adminUserName";
	private static final String ORDERTIME = "orderTime";
	private static final String CHARGEID = "chargeId";
	private static final String ORDERTYPE = "orderType";
	private static final String PAYSTATE = "payState";
	private static final String EFFECTTIME = "effectTime";
	private static final String NOTES = "notes";
	private static final String ISUSED = "isUsed";
	private static final String ALIPAYID = "alipayId";
	private static final String CODE = "code";

	
	@Override
	public List insertModelToList(Object object) {
		Orders orders = (Orders)object;
		List args = new ArrayList();
		args.add(0);
		args.add(orders.getOrderNum());	
		args.add(orders.getUserId());
		args.add(orders.getAdminUserId());
		args.add(orders.getAdminUserName());
		args.add(orders.getOrderTime());
		args.add(orders.getChargeId());
		args.add(orders.getOrderType());
		args.add(orders.getPayState());
		args.add(orders.getEffectTime());
		args.add(orders.getNotes());
		args.add(orders.getIsUsed());
		args.add(orders.getAlipayId());
		args.add(orders.getCode());
		return args;
	}

	@Override
	public Object resultMapper(ResultSet rs, int rowNum) throws SQLException {
		Orders orders = new Orders();
		orders.setId(rs.getLong(ID));
		orders.setOrderNum(rs.getString(ORDERNUM));
		orders.setUserId(rs.getLong(USERID));
		orders.setAdminUserId(rs.getLong(ADMINUSERID));
		orders.setAdminUserName(rs.getString(ADMINUSERNAME));
		orders.setOrderTime(rs.getDate(ORDERTIME));
		orders.setChargeId(rs.getLong(CHARGEID));
		orders.setOrderType(rs.getString(ORDERTYPE));
		orders.setPayState(rs.getInt(PAYSTATE));
		orders.setEffectTime(rs.getDate(EFFECTTIME));
		orders.setNotes(rs.getString(NOTES));
		orders.setIsUsed(rs.getInt(ISUSED));
		orders.setAlipayId(rs.getLong(ALIPAYID));
		orders.setCode(rs.getString(CODE));
		return orders;
	}

	@Override
	public Map updateModelToMap(Object object) {
		Orders orders = (Orders)object;
		Map map = new HashMap();
		map.put(ID, orders.getId());
		map.put(ORDERNUM, orders.getOrderNum());
		map.put(USERID, orders.getUserId());
		map.put(ADMINUSERID, orders.getAdminUserId());
		map.put(ADMINUSERNAME, orders.getAdminUserName());
		map.put(ORDERTIME, orders.getOrderTime());
		map.put(CHARGEID, orders.getChargeId());
		map.put(ORDERTYPE, orders.getOrderType());
		map.put(PAYSTATE, orders.getPayState());
		map.put(EFFECTTIME, orders.getEffectTime());
		map.put(NOTES, orders.getNotes());
		map.put(ISUSED, orders.getIsUsed());
		map.put(ALIPAYID, orders.getAlipayId());
		map.put(CODE, orders.getCode());
		return map;
	}
	
	public String insert(Orders orders){
		return super.insert(orders);
	}
	
	public Orders queryById(Long id){
		return (Orders)super.queryById(id);
	}
	
	public int updateById(Long id, Orders orders) {
		return super.updateById(id, orders);
	}
	
	public int deleteById(Long id) {
		return super.deleteById(id);
	}
	
	public List queryAll(Map<String, Object> map, int start,int end, String... orderByStr){
		return super.queryAll(map, start, end, orderByStr);
	}
}
